﻿using System;
using UnityEngine;

public class HpChangingText : MonoBehaviour
{
    public Color decreaceColor;
    public Color increaseColor;
    [SerializeField]
    private TextMesh m_text;
    public Color playerDecreaceColor;

    public void Refresh(float value, bool isPlayer)
    {
        this.m_text.text = Mathf.Abs(value) + string.Empty;
        this.m_text.color = (value < 0f) ? this.decreaceColor : this.increaseColor;
        if ((value < 0f) && isPlayer)
        {
            this.m_text.color = this.playerDecreaceColor;
        }
    }

    public static void Spwan(Vector3 position, float value, bool isPlayer)
    {
        if (value != 0f)
        {
            GameResources.Effects.HpChangingText.Spawn<HpChangingText>(position).Refresh(value, isPlayer);
        }
    }
}

